import { Controller } from "../../mvc/core/Controller";
import { IView } from "../../mvc/interfaces/IView";
import { CoinCopyModule } from "../../../modules/CoinCopyModule";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { DataEvent } from "../events/DataEvent";
import { ICoinCopyModule } from "../../../modules/interfaces/ICoinCopyModule";
import { ItemData } from "../resource/info/ItemData";
import { AttributeValue } from "../scene/player/AttributeValue";
import { AttributeTextType } from "../scene/player/type/AttributeTextType";
import { SCopyMsgInfo } from "../../../Message/Public/SCopyMsgInfo";
import { MsgManager } from "../manager/MsgManager";
import { Language } from "../../../extend/language/Language";
import { SCoinCopyVerificationCode } from "../../../Message/Public/SCoinCopyVerificationCode";
import { GameProxy } from "../mvc/GameProxy";
type int = number;
//class CoinCopyController
    
    export  class CoinCopyController extends Controller
    {
       

        protected /* override */ initView(): IView
        {
            if (!this._coinCopyModule) 
            {
                this._coinCopyModule = new CoinCopyModule();
            }
            return this._coinCopyModule;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(ServerCommand.CoinCopyEnterCopy, this.onCoinCopyEnterCopy);
            NetDispatcher.addCmdListener(ServerCommand.CoinCopyLeaveCopy, this.onCoinCopyLeaveCopy);
            NetDispatcher.addCmdListener(ServerCommand.CoinCopyCoinBeginPlay, this.onCoinCopyCoinBeginPlay);
            NetDispatcher.addCmdListener(ServerCommand.CoinCopyCoinEndPlay, this.onCoinCopyCoinEndPlay);
            NetDispatcher.addCmdListener(ServerCommand.CoinCopyKillCoinBoss, this.onCoinCopyKillCoinBoss);
            NetDispatcher.addCmdListener(ServerCommand.CoinCopyMsgInfoUpdate, this.onCoinCopyMsgInfoUpdate);
            NetDispatcher.addCmdListener(ServerCommand.CoinCopyEndTimeUpdate, this.onCoinCopyEndTimeUpdate);
            NetDispatcher.addCmdListener(ServerCommand.CoinCopyMsgEnd, this.onCoinCopyMsgEnd);
            NetDispatcher.addCmdListener(ServerCommand.CoinCopyRefreshBoss, this.onCoinCopyRefreshBoss);
            NetDispatcher.addCmdListener(ServerCommand.CoinCopyVerificationCode, this.onCoinCopyVerificationCode);
            Dispatcher.addEventListener(EventName.CoinCopySetCoinNum, this.onCoinCopySetCoinNum);
            Dispatcher.addEventListener(EventName.CoinCopyChangeVerifyCode, this.onCoinCopyChangeVerifyCode);
            Dispatcher.addEventListener(EventName.CoinCopySubmitVerifyCode, this.onCoinCopySubmitVerifyCode);
            Dispatcher.addEventListener(EventName.Scene_Update, this.onSceneUpdate);
            return;
        }

        /* internal  */onSceneUpdate(arg1: DataEvent): void
        {
            if (cache.copy.isInCoinCopy()) 
            {
                (view as ICoinCopyModule).enterCoinCopy();
            }
            return;
        }

        /* internal  */onCoinCopyEnterCopy(arg1: Object): void
        {
            (view as ICoinCopyModule).show();
            return;
        }

        /* internal  */onCoinCopyLeaveCopy(arg1: Object): void
        {
            (view as ICoinCopyModule).leaveCoinCopy();
            (view as ICoinCopyModule).hide();
            return;
        }

        /* internal  */onCoinCopyCoinBeginPlay(arg1: Object): void
        {
            (view as ICoinCopyModule).showMonsterLotteryView();
            return;
        }

        /* internal  */onCoinCopyCoinEndPlay(arg1: int): void
        {
            var coinTime: int;
            var calledItem: ItemData;

            var loc1;
            coinTime = arg1;
            (view as ICoinCopyModule).updateCoinLeftTime(coinTime);
            with ({}) 
            {
            };
            
#error('pushwith') {}
            .flash.utils.setTimeout(
#error('pushwith') {}
            .a = (): void
            {
                (view as ICoinCopyModule).hideMonsterLotteryView();
                return;
            }, 1000)
            calledItem = cache.pack.mountsPackCache.callEdMount;
            if (calledItem == null) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.KeyControllMounts));
            }
            return;
        }

        /* internal  */onCoinCopyKillCoinBoss(arg1: Object): void
        {
            NetDispatcher.dispatchCmd(ServerCommand.RoleSingleAttributeChange, new AttributeValue(AttributeTextType.coin, true, int(arg1)));
            return;
        }

        /* internal  */onCoinCopyMsgInfoUpdate(arg1: Object): void
        {
            (view as ICoinCopyModule).udpateCoinCoyMsg(arg1 as SCopyMsgInfo);
            return;
        }

        /* internal  */onCoinCopyEndTimeUpdate(arg1: int): void
        {
            (view as ICoinCopyModule).updateCoinCopyLeftTime(arg1);
            return;
        }

        /* internal  */onCoinCopyMsgEnd(arg1: SCopyMsgInfo): void
        {
            (view as ICoinCopyModule).updateRewardsMsg(arg1);
            return;
        }

        /* internal  */onCoinCopyRefreshBoss(arg1: int): void
        {
            MsgManager.showTaskTarget(Language.getStringByParam(42000, arg1.toString()));
            (view as ICoinCopyModule).hideCoinTimeView();
            return;
        }

        /* internal  */onCoinCopyVerificationCode(arg1: SCoinCopyVerificationCode): void
        {
            (view as ICoinCopyModule).updateVerifyCode(arg1);
            return;
        }

        /* internal  */onCoinCopySetCoinNum(arg1: DataEvent): void
        {
            GameProxy.copy.setCoinBossNum(int(arg1.data));
            return;
        }

        /* internal  */onCoinCopyChangeVerifyCode(arg1: DataEvent): void
        {
            GameProxy.copy.answerVerificationCode("");
            return;
        }

        /* internal  */onCoinCopySubmitVerifyCode(arg1: DataEvent): void
        {
            var loc1=String(arg1.data);
            GameProxy.copy.answerVerificationCode(loc1);
            return;
        }

        public isInitView(): Boolean
        {
            return !(this._coinCopyModule == null);
        }

        private /* var */_coinCopyModule: ICoinCopyModule;
    }
